//
//  MyHelper.swift
//  EasyTrademarkRegqurySearch
//
//  Created by 伊伊 on 2024/3/14.
//
import Alamofire
import SwiftyJSON
import Foundation

class MyHelper:NSObject{
    @objc static func getImageCodeURL() ->String {
        return URLPathString.getImageCode
    }
    @objc static func sendValidCodeURL() ->String {
        return URLPathString.sendValidCode
    }
    @objc static func checkoutCodeUrl() ->String {
        return URLPathString.regsinCheckcode
    }
    @objc static func unregisterAccountUrl() -> String{
        return URLPathString.unregisterAccount
    }
    
    @objc static func  userAgreementURL() -> String{
        return  LinkURLString.userAgreementURL
    }
    
    @objc static func  privacyPolicyURL() -> String{
        return  LinkURLString.privacyPolicyURL
    }
    
    
    @objc static func shanYan_id() -> String{
        return ParameterConstant.shanYanAPPID
    }
    
    
    @objc static func device_id() -> String{
        return ParameterConstant.device_id
    }

    @objc static func device_model() -> String{
        return UIDevice.current.modelName
    }
    
}


class AFNRequest:NSObject,Requestable{
    private var urlString = ""
    private var dic = [String:String]()
    private var header = [String:String]()
    
    private var afnMethod:HTTPMethod = .post
    
    var path: String {
        return self.urlString
    }
    
    var parmeters: [String : String]{
        return self.dic
    }
    
    var method: HTTPMethod{
        return self.afnMethod
    }
    
    
    
    @objc  func POST(url:String,parmeters:[String:String],success: @escaping (_ responseJson:Any?) -> Void,failure: @escaping (_ error:Error?)  -> Void){
        self.urlString = url
        self.dic = parmeters
        self.afnMethod = .post
        
        self.fetchData({ responseJson in
            
            switch responseJson{
                
            case .success(let data):
                success(data.object)
                
            case .failure(let error):
                failure(error)
            }
        }, showErrorHud: false)
        
    }

    @objc  func GET(url:String,parmeters:[String:String], success: @escaping (_ responseJson:Any?) -> Void,failure: @escaping (_ error:Error?)  -> Void){
        self.urlString = url
        self.dic = parmeters
        self.afnMethod = .get
        
        self.fetchData({ responseJson in
            
            switch responseJson{
                
            case .success(let data):
                success(data.object)
                
            case .failure(let error):
                failure(error)
            }
        }, showErrorHud: false)

    }

}

